package com.qiwx.pigeon.presenter;


import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.CageParam;
import com.qiwx.pigeon.data.vo.CageBeanVo;
import com.qiwx.pigeon.data.vo.FertilizeBean;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.viewinterface.ICageView;

import java.lang.ref.WeakReference;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * @description
 * @Author qiwx
 * @Date 2020-04-16 11:30
 *
 **/
public class CagePresenter extends BasePresenter<ICageView> {

    public CagePresenter(WeakReference<ICageView> from) {
        super(from);
    }

    //添加鸽笼
    public void addCage(CageParam params) {
        ApiManager.getApiServer().addCage(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<Integer>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<Integer> response) {
                        getView().onAddCageSuccess(response.data);
                    }

                });
    }

    //查询鸽笼
    public void queryCagesByPage(CageParam params) {
        ApiManager.getApiServer().queryCagesByPage(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<PageInfo<CageBeanVo>>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<PageInfo<CageBeanVo>> response) {
                        getView().onQueryCageSuccess(response.data);
                    }

                });
    }
    //更新鸽笼状态
    public void updateCageStatus(CageParam params) {
        ApiManager.getApiServer().updateCageStatus(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<Integer>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<Integer> response) {
                        getView().onUpdateCageSuccess(response.data);
                    }

                });
    }
    //查询空窝
    public void getKWListByPage(CageParam params) {
        ApiManager.getApiServer().getKWListByPage(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<PageInfo<CageBeanVo>>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<PageInfo<CageBeanVo>> response) {
                        getView().onQueryCageSuccess(response.data);
                    }

                });
    }







}
